#include "eGUI.hpp"
void * eGUI_Page::operator new(std::size_t size)
{
    return eGUI_Malloc(size);
}
void eGUI_Page::operator delete(void* ptr)
{
    if (ptr)
        eGUI_Free(ptr);
}

//ARMCC5 对构造函数执行O0优化避免this==NULL被优化掉
#pragma push
#pragma O0
eGUI_Page::eGUI_Page(eGUI_PAGE_TYPE Type, void (*Ctrlcb)(uint32_t), void (*Viewcb)(eGUI_Page*))
{
    if (this == NULL) return;
    this->type = Type;
    this->autoFlashOpen();
    if (Type == eGUI_PAGE_TYPE_TEXTLIST)
    {
        this->u.textList = new eGUI_TextList(egui);
        if (this->u.textList == NULL)
            this->type = eGUI_PAGE_TYPE_NULL;
    }
    this->viewcb = Viewcb;
    this->ctrlcb = Ctrlcb;
}
eGUI_Page::eGUI_Page(eGUI_Graph *eGUI_Graph, void (*Ctrlcb)(uint32_t), void (*Viewcb)(eGUI_Page*))
{
    this->u.graph = eGUI_Graph;
    this->autoFlashOpen();
    if (this->u.graph == NULL)
        this->type = eGUI_PAGE_TYPE_NULL;
    this->viewcb = Viewcb;
    this->ctrlcb = Ctrlcb;
}
eGUI_Page::eGUI_Page(eGUI_InputBox *InputBox)
{
    this->u.inputBox = InputBox;
    this->autoFlashOpen();
    this->type = eGUI_PAGE_TYPE_INPUTBOX;
    this->viewcb = NULL;
    this->ctrlcb = NULL;
}
#pragma pop


void eGUI_Page::autoFlashClose(void)
{
    this->autoFlash = false;
}

void eGUI_Page::autoFlashOpen(void)
{
    this->autoFlash = true;
}
